//
//  Person.m
//  06_Homework
//
//  Created by 徐昊 on 16/7/8.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "Person.h"

@implementation Person

- (instancetype)initWithName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender{
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _gender = gender;
    }
    return self;
}

+ (instancetype)personWithName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender{
    return [[[Person alloc] initWithName:name age:age gender:gender] autorelease];
}
- (NSString *)description {
    return [NSString stringWithFormat:@"name = %@, age = %ld gender = %@", _name, _age, _gender];
}
- (NSComparisonResult)compareWithName:(Person *)person {
    return [self.name compare:person.name];
}
- (NSComparisonResult)compareWithAge:(Person *)person {
    return [[NSString stringWithFormat:@"%ld", self.age] compare:[NSString stringWithFormat:@"%ld", person.age]];
}
- (NSComparisonResult)compareWithSex:(Person *)person {
    return [self.gender compare:person.gender];
}
@end
